<h1>Enter Feedback</h1>
<p>Select an assessment item and student to enter grades and reviews for. </p>

<script type="text/javascript">
	function validateForm() {
		var grade = $('#grade').attr('value');
		grade = parseInt(grade, 10);
		if (grade < 1 || grade > 7) {
			alert("Please enter a grade between 1 and 7.");
			return false;
		} else if (isNaN(grade)) {
			alert("Please enter a grade between 1 and 7.");
			return false;
		}
		return true;
	}
</script>

<form action="<?php echo site_url('admin/enter_feedback'); ?>" method="POST" onsubmit="return validateForm()"  >

	<label for="assessment_id">Assessment Item</label>
	<select name="assessment_id" id="assessment_id">
		<?php foreach($assessments as $key => $assesment ) : ?>
		<option value="<?php echo $assesment['assessment_id']; ?>"><?php echo $assesment['assessment_title']; ?></option>
		<?php endforeach; ?>
	</select>

	<br>

	<label for="user_id">Student</label>
	<select name="user_id" id="user_id">
		<?php foreach($students as $key => $student ) : ?>
		<option value="<?php echo $student['user_id']; ?>"><?php echo $student['first_name'] . ' ' . $student['last_name']; ?></option>
		<?php endforeach; ?>
	</select>

	<br>

	<label for="grade">Grade (Out of 7)</label>
	<input type="text" name="grade" id="grade" style="width:50px">

	<br>

	<label for="review">Feedback</label>
	<textarea name="review" id="" cols="30" rows="10"></textarea>

	<br>

	<input type="submit" value="Enter Feedback" />

</form>


<h1>Existing Feedback</h1>

<table>
	
	<tr>
		<th>Assessment Item</th>
		<th>Student Name</th>
		<th>Grade</th>
		<th>Feedback</th>
		<th>Delete</th>
	</tr>

	<?php if ( is_array($student_feedback) ) : ?>
	<?php foreach ($student_feedback as $feedback) : ?>
		<tr>
			<td><?php echo $feedback['assessment_title']; ?></td>
			<td><?php echo $feedback['first_name'] . ' ' . $feedback['last_name']; ?></td>
			<td><?php echo $feedback['grade']; ?></td>
			<td><?php echo $feedback['review']; ?></td>
			<td><a href="<?php echo site_url('admin/delete_feedback'); ?>/<?php echo $feedback['review_id']; ?>">Delete Feedback</a></td>
		</tr>
	<?php endforeach ?>
	<?php else : ?>
	<p>No feedback has been entered yet.</p>
	<?php endif; ?>

</table>